package threadtask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import orm.po.ListeningInfo;
import service.ListeningService;

import java.util.List;

/**
 * @author yuyufeng
 * @date 2018/2/7
 */
public class MainTask implements Runnable {
    private ListeningService listeningService;
    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    public MainTask(ListeningService listeningService) {
        this.listeningService = listeningService;
    }

    @Override
    public void run() {
        while (true) {
            LOG.info(".............一轮监听开始......."+Thread.currentThread().getName());
            int page = 1;
            while (true) {
                List<ListeningInfo> list = listeningService.listListeningList(page, 10);

                if (list != null && list.size() > 0) {
                    page++;
                } else {
                    break;
                }

                for (ListeningInfo listeningInfoPO : list) {
                    // 0,火车票有票提醒
                    // 1,火车票过少提醒
                    // 2,汽车票有票提醒
                    // 3,汽车票过少提醒
                    Integer listeningType = listeningInfoPO.getListeningType();
//                System.out.println(listeningInfoPO);
                    if (listeningType == 0 || listeningType == 1) {
//                    System.out.println("火车票监听");
                        listeningService.listeningTrainItem(listeningInfoPO);
                    } else if (listeningType == 2 || listeningType == 3) {
//                    System.out.println("汽车票监听");
                        listeningService.listeningBusItem(listeningInfoPO);
                    }
                }
            }
        }
    }
}
